﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            //DateTime startTime = DateTime.Now;
            //Singlethread singleThread=new Singlethread();
            //singleThread.Start();
            //DateTime endTime = DateTime.Now;
            //TimeSpan ts = endTime.Subtract(startTime);
            //Console.WriteLine(ts.Milliseconds);

            //Multithread multiThread = new Multithread();
            //multiThread.Start();

            #region Producer/Consumer

            int _request = 200;

            int result = 0; //一个标志位，如果是0表示程序没有出错，如果是1表明有错误发生
            Cell cell = new Cell();
            CellProducer prodcuer = new CellProducer(cell, _request);
            CellConsumer consumer = new CellConsumer(cell, _request);

            Thread producerThread = new Thread(prodcuer.ThreadRun);
            Thread consumerThread = new Thread(consumer.ThreadRun);

            try
            {
                producerThread.Start();
                consumerThread.Start();
            }
            catch (ThreadStateException e)
            {
                Console.WriteLine(e);
                result = 1;
            }
            catch(ThreadInterruptedException e)
            {
                //当线程在等待状态的时候中止
                Console.WriteLine(e);
                result = 1;
            }
            //尽管Main()函数没有返回值，但下面这条语句可以向父进程返回执行结果
            Environment.ExitCode = result;
            #endregion
        }
    }

    public class Comment
    {
        public int ID { get; set; }
        public string Title { get; set; }
        public string Content { get; set; }
    }
}
